from django.shortcuts import render,redirect
from .import models

# Create your views here.
def index(request):
    if request.method == 'GET':
        return render(request,'index.html')
def login(request):
    if request.method == 'GET':
        return render(request,'login.html')
    elif request.method == 'POST':
        #用户提交表单
        username = request.POST.get('username')
        password = request.POST.get('password')
        #查询数据库      'select * from login_user where name=%s and password=%s' %(username,password)
        user = models.User.objects.filter(name=username,password=password).first()
        if not user:
            #登录失败
            print('用户名或密码错误')
            return redirect('/login/')

        #登陆成功
        print('登录成功')
        return redirect('/index/')

def register(request):
    return render(request, 'register.html')

def logout(request):
    pass
